#import <Foundation/Foundation.h>
#import <objc/runtime.h>
#import <UIKit/UIKit.h>
#import <UIKit/UIApplication.h>
#import <Preferences/PSSpecifier.h>

#import "framework/FWCommon.h"

#import "PIAboutPrefs.h"


@implementation PIAboutPrefs


// ******************************************************************************************
#pragma mark -
#pragma mark Initialisation and object management

- (void)dealloc
{
    [_specifiers release];
    _specifiers = nil;
    
    [super dealloc];
}


// ******************************************************************************************
#pragma mark -
#pragma mark Get about page

- (NSArray *)specifiers
{
    if (!_specifiers) {
        NSString* key = [[self specifier] propertyForKey:@"key"];
        DebugLog(@"LI:PICommon: Loading specifiers from %@", key);

        NSArray* specs = [self loadSpecifiersFromPlistName:key target:self];
        specs = [self localizedSpecifiersForSpecifiers:specs];

        _specifiers = [specs retain];
    }
    
    return _specifiers;
}

- (NSArray*)localizedSpecifiersForSpecifiers:(NSArray*)specs
{
    DebugLog(@"LI:PICommon: Specifiers %@", specs);
    NSBundle* bundle = [NSBundle bundleForClass:[self class]];

    for (PSSpecifier* spec in specs) {
        if (NSString* name = [spec name]) {
            [spec setName:localize(bundle, name)];
            
            if (NSString* footer = [spec propertyForKey:@"footerText"])
                [spec setProperty:localize(bundle, footer) forKey:@"footerText"];
        }
    }

    return specs;
}

-(id)navigationTitle
{
    return localize([self bundle], [super _title]);
}

@end
